<?php
namespace app\models;

use fastphp\base\Model;

class StringFunction extends Model
{
    public static function decodeUnicode($str)
    {
        return preg_replace_callback("#\\\u([0-9a-f]+)#i",function($m){return iconv('UCS-2','UTF-8', pack('H4', $m[1]));},$str);
    }
    public static function decodeUnicodeArray($arr)
    {
        foreach($arr as $x) {
            $x = $this->decodeUnicode($x);
        }
        return $arr;
    }
    public static function htmlspecialcharsArray($target = null)
    {
        if (is_array($target)) {
            $target = array_map([__CLASS__, 'htmlspecialcharsArray'], $target);
        } else {
            $target = htmlspecialchars($target);
        }
        return $target;
    }
    public static function getLanguageClass($language)
    {
        if (strpos($language, "c++") !== FALSE)
            return "language-cpp";
        elseif ($language == "c99")
            return "language-c";
        elseif (strpos($language, "python") !== FALSE)
            return "language-python";
        elseif (strpos($language, "lua") !== FALSE)
            return "language-lua";
        elseif (strpos($language, "php") !== FALSE)
            return "language-php";
        elseif (strpos($language, "assembly") !== FALSE)
            return "language-asm6502";
        else
            return "language-cpp";
    }
}